﻿using UnityEditor;

namespace BToolkit
{
    [CustomEditor(typeof(BButton))]
    public class BButtonEditor : Editor
    {
        SerializedProperty index, canTriggerInterval, sound, isDownSound, isClickSound, listenKeyBack;

        //点击变换效果
        SerializedProperty transition;
        SerializedProperty transTarget;
        SerializedProperty pressScale, pressColor, pressTexture;

        void OnEnable()
        {
            index = serializedObject.FindProperty("index");
            canTriggerInterval = serializedObject.FindProperty("canTriggerInterval");
            sound = serializedObject.FindProperty("sound");
            isDownSound = serializedObject.FindProperty("isDownSound");
            isClickSound = serializedObject.FindProperty("isClickSound");
            listenKeyBack = serializedObject.FindProperty("listenKeyBack");

            //点击变换效果-Begin
            transition = serializedObject.FindProperty("transition");
            transTarget = serializedObject.FindProperty("transTarget");
            pressScale = serializedObject.FindProperty("pressScale");
            pressColor = serializedObject.FindProperty("pressColor");
            pressTexture = serializedObject.FindProperty("pressTexture");
            //点击变换效果-End
        }

        public override void OnInspectorGUI()
        {
            EditorGUILayout.PropertyField(index);
            EditorGUILayout.PropertyField(canTriggerInterval);
            EditorGUILayout.PropertyField(sound);
            if (!sound.objectReferenceValue)
            {
                EditorGUILayout.PropertyField(isDownSound);
                EditorGUILayout.PropertyField(isClickSound);
            }
            EditorGUILayout.PropertyField(listenKeyBack);

            //点击变换效果-Begin
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(transition);
            if (transition.enumValueIndex > 0)
            {
                EditorGUILayout.PropertyField(transTarget);
                if (transition.enumValueIndex == (int)BButton.Transition.Scale)
                {
                    EditorGUILayout.PropertyField(pressScale);
                }
                else if (transition.enumValueIndex == (int)BButton.Transition.Color)
                {
                    EditorGUILayout.PropertyField(pressColor);
                }
                else
                {
                    EditorGUILayout.PropertyField(pressTexture);
                }
            }
            //点击变换效果-End

            serializedObject.ApplyModifiedProperties();
        }
    }
}